package com.guigu.yh.springcloud.controller;

import com.guigu.yh.springcloud.common.JsonResult;
import com.guigu.yh.springcloud.entities.Payment;
import com.guigu.yh.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.Resources;

/**
 * 假装顺序控制方法
 *
 * @author 张颖辉（zyh）
 * @version 1.0.0
 * @date 2022/08/21
 */
@Slf4j
@RestController
public class OrderFeignConroller {
    @Resource
    private PaymentFeignService paymentFeignService;

    @RequestMapping("payment/get/{id}")
    public JsonResult<Payment> getPayment(@PathVariable("id") Long id) {
        JsonResult<Payment> jsonResult = paymentFeignService.getPayment(id);
        return jsonResult;
    }

    /**
     * 测 feign 时间： feign client 超时时间默认1秒，
     * 当前测试接口3秒返回，触发超时异常：[Request processing failed; nested exception is feign.RetryableException: Read timed out executing GET http://CLOUD-PAYMENT-SERVICE/payment/testFeignTimeOut] with root cause
     *
     * @return {@link JsonResult }
     * @author zyh
     * @date 2022/08/22
     * @version 1.0.0
     */
    @RequestMapping("payment/testFeignTimeOut")
    public JsonResult testFeignTimeOut() {
        String paymentPort = paymentFeignService.testFeignTimeOut();
        return new JsonResult<String>("200","测试Feign 3秒后响应",paymentPort);
    }
}
